package com.dxf.sysadmin.controller;
import com.dxf.common.utils.ResultJson;
import com.dxf.sysadmin.entity.SysUser;
import com.dxf.sysadmin.entity.po.SysUserPo;
import com.dxf.sysadmin.entity.qo.SysUserQo;
import com.dxf.sysadmin.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import sun.plugin.util.UIUtil;


import java.util.List;

@RestController
@RequestMapping("/admin/user")
@Api(tags  = "SysUserController|用户控制器")
@Slf4j
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * @Description: 用户列表分页查询
     */
    @PostMapping("userPage")
    @PreAuthorize("@el.check('user.detail')")
    @ApiOperation("用户列表分页查询")
    public ResultJson userPage(@RequestBody SysUserQo qry){
        return sysUserService.userPage(qry);
    }

    /**
     * @Description: 更具id删除用户
    @PostMapping("delete")
    @PreAuthorize("@el.check('user.delete')")
    @ApiOperation(value = "更具id列表删除用户")
    public ResultJson deleteUser(@RequestParam("uidList[]") List<Long>  uidList){
        return sysUserService.deleteUser(uidList);
    }

    /**
     * @Description: 新增或者更新用户
     */
    @PostMapping("saveOrUpdate")
    @PreAuthorize("@el.check('user.add','user.modiy')")
    @ApiOperation(value="新增或者更新用户")
    public ResultJson saveOrUpdate( @RequestBody SysUserPo po){
        return sysUserService.saveOrUpdate(po);
    }

    /**
     * @Description: 获取所有角色
     */
    @GetMapping("getRoles")
    @ApiOperation(value="获取所有角色")
    public ResultJson getRoles(){
        return sysUserService.getRoles();
    }

    /**
     * @Description: 获取对象和角色关系详情
     */
    @GetMapping("before/{uid}")
    @ApiOperation(value="获取对象和角色关系详情")
    @ApiImplicitParam(paramType="path", name = "uid", value = "用户id")
    public ResultJson details(@PathVariable Long uid){
        return sysUserService.details(uid);
    }


    /**
     * @Description: 重置密码
     */
    @PutMapping("resetPWD/{id}")
    @ApiOperation(value = "重置密码")
    public ResultJson resetPWD(@PathVariable Long id){
        return sysUserService.resetPWD(id);
    }

    @GetMapping("getInfo/{token}")
    @ApiOperation(value = "更具token获取角色信息")
    public ResultJson getInfo(@PathVariable String token){
        return sysUserService.getInfo(token);
    }

}